<?php
//用于SEO搜索引擎
namespace App\Http\Controllers;

use App\Article;
use App\Data;
use App\Http\Resources\ArticleCollection;
use App\Http\Resources\DataCollection;
use Illuminate\Http\Request;


class SeoDetailController extends Controller
{
    //模型详情
    public function modeldetail( $type,$id, $method)
    {
        $where['is_del'] = 0;
        $info = Data::where($where)->findOrfail($id);
        $info->viewnum += 1;
        $info->save();
        $data['type'] = $type;
        $data['typenameroute'] = gettypename($type);
        $data['detail'] = $info;
        //随机推荐
        $data['nearby'] =  new DataCollection(Data::where($where)->inRandomOrder()->where('id', '!=',$id)->limit(4)->get());
        return view('detail',$data);
    }
    //案例详情
    public function articledetail($type, $id, $method)
    {
        $where['is_del'] = 0;
        $info = Article::where($where)->findOrfail($id);
        $info->viewnum += 1;
        $info->save();
        $data['type'] = $type;
        $data['typenameroute'] = gettypename($type);
        $data['detail'] = $info;
        $where['cat_id2'] = $info->cat_id2;
        //随机推荐
        $data['nearby'] =  new ArticleCollection(Article::where($where)->inRandomOrder()->where('id', '!=',$id)->limit(4)->get());
        return view('articledetail',$data);
    }

}
